package com.roadmap.ui;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;

import com.roadmap.common.BaseConst;
import com.roadmap.common.RdcResourceBundle;

public class HTMLComponentWriter {
	private JspWriter _out;
	
	public HTMLComponentWriter(JspWriter out) {
		this._out = out;
	}
	
	public void writeGoalPrioritySelect(String selectId)
			throws IOException {
		_out.write(String.format("<select id='%s' class='input-text'>", selectId));
		for (int i = 0; i < RdcResourceBundle.ENTITY_PRIORITY_DESCRIPTIONS.length; i++) {
			String selected = i == BaseConst.ENTITY_PRIORITY_MEDIUM ? "selected"
					: null;
			String htmlContent = String
					.format("<option value='%s' %s>%s</option>",
							RdcResourceBundle.ENTITY_PRIORITY_DESCRIPTIONS[i],
							selected,
							RdcResourceBundle.ENTITY_PRIORITY_DESCRIPTIONS[i]);
			_out.write(htmlContent);
		}
		_out.write("</select>");
	}
	
	public void writeGoalStatusSelect(String selectId, String display) throws IOException {
		_out.write(String.format("<select id='%s' class='input-text'>", selectId));
		for(int i = 0; i < RdcResourceBundle.LIFEGOAL_STATUS_DESCRIPTIONS.length; i++){
			String htmlContent = String.format("<option value='%s'>%s</option>", 
					RdcResourceBundle.LIFEGOAL_STATUS_DESCRIPTIONS[i],
					RdcResourceBundle.LIFEGOAL_STATUS_DESCRIPTIONS[i]);
			_out.write(htmlContent);	
		}
		_out.write("</select>");
	}
	
	public void writeVisibilitySelect(HttpServletRequest request) throws IOException {
		_out.write("<select id='limitedAccess' class='input-text'>");
		Integer accessLevel = (Integer) request.getAttribute("accessLevel");
		int index = (accessLevel == null) ? BaseConst.ENTRY_VISIBILITY_PROTECTED : accessLevel.intValue();
		for (int i = 0; i < RdcResourceBundle.ENTITY_VISIBILITY_DESCRIPTIONS.length; i++){
			String selected = (i == index) ? "selected" : null;
			_out.write(String.format("<option value='%s' %s>%s</option>", 
					RdcResourceBundle.ENTITY_VISIBILITY_DESCRIPTIONS[i], 
					selected, 
					RdcResourceBundle.ENTITY_VISIBILITY_DESCRIPTIONS[i]));
		}
		_out.write("</select>");
	}
}
